<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>全局组件</title>
		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="app">
			<button-counter></button-counter>
			<button-counter></button-counter>
			<button-counter></button-counter>
			<hello-world></hello-world>
		</div>
		<script>
			//声明组件
			Vue.component("button-counter", {
				data: function() {
					//返回结果必须为对象类型.通过函数形成闭包的结构
					return {
						num: 0
					};
				},
				template: `<div>
								<div>
								 num的值为:{{num}}
								</div>
								<button @click="handle">单击</button>
								<HelloWorld></HelloWorld>
								<hello-world></hello-world>
						   </div>`,
				methods: {
                     handle:function(){
						 this.num+=2;
					 }
				}

			});
			
			//驼峰的命名方式
			Vue.component("HelloWorld",{
				data:function(){
					return {msg: 'hello Component'}
				},
				template:`<h3>{{msg}}</h3>`
			});

			let vm = new Vue({
				el: '#app',
			});
		</script>
	</body>
</html>
